//
// Created by bangsun on 2022/10/15.
//
#include "include/switch.h"
#include "include/time_sched.h"
#include "include/gmp.h"
#include <stdatomic.h>

static pthread_mutex_t mutex;

void func1(void *arg) {
    printf("hello, I'm fun1111 ,arg is %x,tid is %d\n", arg, getpid());
}

void func2(void *arg) {

    printf("hello, I'm fun2222 ,arg is %x,tid is %d\n", arg, getpid());
    fflush(stdout);
    int asd = 0;
    for (int i = 0; i < 100; i++) {
        asd += 1;
    }
}

void testcall() {
    printf("this is test call\n");
}

void test_atomic() {
    int x = 111, y = 111;
    int v1 = atomic_compare_exchange_strong(&x, &y, 123);
    int v2 = atomic_compare_exchange_strong(&x, &y, 123);
    printf("v1:%d,v2:%d,x:%d", v1, v2, x);

}


void test_loutine1() {
    init_loutine_environment();
    pthread_mutex_init(&mutex, NULL);
    for (int i = 0; i < 1e4; i++) {
        const int thisi = i;
        create_loutine(func2, thisi);
    }
    for (;;);

}

void test_loutine2() {
    init_loutine_environment();
    pthread_mutex_init(&mutex, NULL);
    create_loutine(func2, 0);
    for (;;);

}

// | <self area> |eflags|eax|edx|ecx|ebx|esi|edi|ebp|<eip>(prev)
//               -> stack index increase
//                            stack grow direction <-
int main() {
//    test_atomic();
//    test_timer();
    test_loutine1();

}



